package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.sc.nft.entity.IntegralDetailsVO;
import com.sc.nft.enums.AssetChangeLogEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.AssetChangeLog;
import com.sc.nft.mapper.AssetChangeLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * (sc_asset_change_log)数据DAO
 *
 * @author rdg
 * @since 2022-05-30 10:42:05
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class AssetChangeLogDao extends ServiceImpl<AssetChangeLogMapper, AssetChangeLog> {

    public Page<AssetChangeLog> pageAssetsChangeList(Long userId, Integer type, Date startDate, Date endDate, int pageNo, int pageSize) {
        LambdaQueryWrapper<AssetChangeLog> assetChangeLogLambdaQueryWrapper = new LambdaQueryWrapper<>();
        assetChangeLogLambdaQueryWrapper.eq(AssetChangeLog::getUserId,userId);
        assetChangeLogLambdaQueryWrapper.eq(type!=null,AssetChangeLog::getType,type);
        assetChangeLogLambdaQueryWrapper.eq(AssetChangeLog::getAssetId,1);
        assetChangeLogLambdaQueryWrapper.between(startDate!=null&&endDate!=null,AssetChangeLog::getCreateTime,startDate,endDate);
        assetChangeLogLambdaQueryWrapper.orderByDesc(AssetChangeLog::getAssetId);
        assetChangeLogLambdaQueryWrapper.orderByDesc(AssetChangeLog::getId);
        return page(new Page<>(pageNo,pageSize),assetChangeLogLambdaQueryWrapper);
    }

    public Page<IntegralDetailsVO> integralDetails(Integer pageNo, Integer pageSize, Long userId) {
        return baseMapper.integralDetails(new Page(pageNo,pageSize),userId);
    }

    public Page<IntegralDetailsVO> integralDetailsByType(@NotNull Long userId,Integer type, Integer pageNo, Integer pageSize) {
        List<Integer> types = Lists.newArrayList();
        if(type!=null){
            types = AssetChangeLogEnum.getCodeListByIsAdd(type.intValue()==1);
        }
        return baseMapper.integralDetailsByType(new Page(pageNo,pageSize),userId,types);
    }


}